package com.woniu.model.gh.common.exception;

import com.woniu.model.gh.common.Result;
import com.woniu.model.gh.common.enums.IResultCode;
import com.woniu.model.gh.common.enums.impl.ResultCode;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

//处理全局异常
@Component("medical_service_global_exception")
@RestControllerAdvice
public class GlobalException {

    //通过@ExceptionHandler注解，指定要处理的异常类型
    @ExceptionHandler(BusinessException.class)
    public Result<Void> handlerBusinessException(BusinessException e) {
        //e.printStackTrace();
        IResultCode resultCode = e.getResultCode();
        return Result.fail(resultCode);
    }

    //处理其它未明确指定的所有异常
    @ExceptionHandler(Exception.class)
    public Result<Void> handlerBusinessException(Exception e) {
        e.printStackTrace();
        return Result.fail(ResultCode.FAIL);
    }

}
